{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "module_path = os.path.abspath(os.path.join('..'))\n",
    "if module_path not in sys.path:\n",
    "    sys.path.append(module_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%env OPENAI_API_KEY=<Enter you key here>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "from IPython.core.display import HTML\n",
    "\n",
    "from engine.utils import ProgramGenerator, ProgramInterpreter\n",
    "from prompts.imgedit import PROMPT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "interpreter = ProgramInterpreter(dataset='imageEdit')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_prompt(instruction):\n",
    "    return PROMPT.format(instruction=instruction)\n",
    "\n",
    "generator = ProgramGenerator(prompter=create_prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "image = Image.open('../assets/bollywood.png')#.resize((512,512))\n",
    "image.thumbnail((512,512),Image.Resampling.LANCZOS)\n",
    "init_state = dict(\n",
    "    IMAGE=image.convert('RGB')\n",
    ")\n",
    "image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "instruction = \"Replace man in black henley (person) with brick wall\"\n",
    "# instruction = \"Hide Salman and Aamir's faces with :ps, Shahrukh's faces with 8) and Hritik's with ;)\"\n",
    "# instruction = \"Create a colorpop of the man in black henley and also blur the background\"\n",
    "prog,_ = generator.generate(instruction)\n",
    "print(prog)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result, prog_state, html_str = interpreter.execute(prog,init_state,inspect=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTML(html_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('few-shot-vr')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "f6aae81381dc24e2fd0d8778e266667bb8dbd7e1c04425e21584f774a2d20c40"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
